from django.db import models
from utils.models import BaseModel


# Create your models here.
class ContentCategory(BaseModel):
    name = models.CharField(max_length=50, verbose_name='Category Name')
    key = models.CharField(max_length=50, verbose_name='Category Key')

    class Meta:
        db_table = 'tb_content_category'
        verbose_name = 'Content category'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Content(BaseModel):
    category = models.ForeignKey(ContentCategory, on_delete=models.PROTECT, verbose_name='Content category id')
    title = models.CharField(max_length=100, verbose_name='Title')
    url = models.CharField(max_length=300, verbose_name='URL')
    image = models.ImageField(null=True, blank=True, verbose_name='image')
    text = models.TextField(null=True, blank=True, verbose_name='Text')
    sequence = models.IntegerField(verbose_name='sort')
    status = models.BooleanField(default=True, verbose_name='Visible')

    class Meta:
        db_table = 'tb_content'
        verbose_name = 'Advertisement content'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category.name + ': ' + self.title


